define(function(require,exports,module){
	var Form = require("form");
	var store = require("store");
	var Button = require("button");
	var Dialog = require("dialog");
	
	module.exports = {
		initComponent: function(widget){
			var form = new Form({
				parentNode: ".J-form",
				model: {
					id: "form",
					layout: "3_1",
					saveaction: function(){
						widget.handler.form.handleSaveBtnClick(widget);
					},
					cancelaction: function(){
						widget.handler.form.handleCancelBtnClick(widget);
					},
					items: [{
						name: "planItemGroup",
						type: "hidden"
					},{
						name: "version",
						type: "hidden",
						defaultValue: "0"
					},{
						name: "destination",
						type: "hidden"
					},{
						name: "destinationName",
						label: "目的地",
						readonly: true
					},{
						name: "startDate",
						label: "开始日期",
						type:"date",
						readonly: true
					},{
						name: "endDate",
						label: "结束日期",
						type:"date",
						readonly: true
					},{
						name: "signUpNumber",
						label: "报名人数",
						readonly: true
					},{
						name: "reserveDate",
						label: "预约日期",
						type: "date",
						defaultValue: moment().format("YYYY-MM-DD"),
						readonly: true
					},{
						name: "operator",
						type: "hidden",
						defaultValue: store.get("user").pkUser,
						readonly: true
					},{
						name: "operatorName",
						label: "经办人",
						defaultValue: store.get("user").name,
						readonly: true
					},{
						name: "checkInDate",
						label: "入住日期",
						type: "date",
						validate:["required"],
						events: {
							"change": function(e){
								var form = widget.get("form");
				        		var startDate = form.getValue("checkInDate");
				        		var endDate = form.getValue("checkOutDate");
				        		if(startDate !="" && endDate != "" && startDate > endDate && $(".modal").length == 0){
				        			Dialog.alert({
				        				tip : "提示",
				        				content : "退房日期不能晚于入住日期！"
				        			})
				        		}
							}
						 }
					},{
						name: "checkOutDate",
						label: "退房日期",
						type: "date",
						validate:["required"],
						events: {
							"change": function(e){
								var form = widget.get("form");
				        		var startDate = form.getValue("checkInDate");
				        		var endDate = form.getValue("checkOutDate");
				        		if(startDate !="" && endDate != "" && startDate > endDate && $(".modal").length == 0){
				        			Dialog.alert({
				        				tip : "提示",
				        				content : "退房日期不能晚于入住日期！"
				        			})
				        		}
							}
						 },
					},{
						name: "checkInType",
						label: "入住机构",
						type: "select",
						options: [{
							key: "Organization",
							value: "直属机构"
						},{
							key: "Alliance",
							value: "联盟机构"
						}],
						validate:["required"],
						defaultValue: "Organization",
						events: {
							change: function(){
								widget.handler.form.handleCheckInTypeChange(widget);
							}
						}
					},{
						name:"roomType",
						label:"房型"
					},{
						name: "allianceBuilding",
						label: "楼宇",
						type: "textarea",
						height: 50,
						validate:["required"]
					},{
						name: "rooms",
						label: "预定房间",
						type: "textarea",
						height: 50,
						validate:["required"]
					},{
						name: "description",
						label: "预定说明",
						type: "textarea",
						height: 50
					}]
				}
			});
			widget.set("form",form);
			
			var btn = new Button({
				parentNode: ".J-form-form-textarea-rooms",
				model: {
					text: "预定",
					handler: function(){
						widget.handler.form.handleAppointBtnClick(widget);
					}
				}
			});
			widget.set("btn",btn);
		}
	};
});